package com.gx.smart.building.ui.warning.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemWarningRecordLayoutBinding;
import com.gx.smart.lib.http.api.response.MessageAlarm;

/**
 * @author: xiaosy
 * 时间: 2022/4/7
 * @Description: java类作用描述
 * @Version: 1.0
 **/
public class WarningAdapter extends BaseAdapter<MessageAlarm, WarningAdapter.ViewHolder> {
    public WarningAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_warning_record_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemWarningRecordLayoutBinding binding = ItemWarningRecordLayoutBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, MessageAlarm item, int position) {
        holder.binding.alarmTypeName.setText(item.getAlarmTypeName());
        holder.binding.alarmLevelName.setText(item.getAlarmLevelName());
        holder.binding.alarmDetail.setText(item.getAlarmDetail());
        holder.binding.areaName.setText("告警地点: " + item.getAreaName());
        String time = TimeUtils.millis2String(item.getAlarmTime(), "yyyy-MM-dd HH:mm:ss");
        holder.binding.alarmTime.setText("告警时间: " + time);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ItemWarningRecordLayoutBinding binding;

        public ViewHolder(ItemWarningRecordLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
